<!-- #INCLUDE File="lib.asp" -->

<%

dim page, nextpage

pauze = 18

command = request("command")

select case command
case "preview"
	titel = request("titel")
	inhoud = request("inhoud")
	inhoud = replace(inhoud,vbcrlf,"<br>")
	bgnr = request("imgnr")
	bgnr = cstr(cdbl(bgnr))
	special = request("special")
	special = cstr(cdbl(special))
	thispage = request("thispage")

	if special > 0 then
		sql = "select include from special where id=" & special
		rs = tmpConnection.execute(sql)
		theInc = rs("include")
	end if
	
	sql = "select image from images where id=" & bgnr
	rs = tmpConnection.execute(sql)
	bgImage = rs("image")
	
	closeDatabase
	
	if special = 0 then
		showpage
	else
		' http://studio.lokaleomroepkrimpen.nl:81/kabelkrant/special/youtube/playvid2.asp?a=0&nextpage=30&id=vKKn6B5tC0Y
		response.redirect "special/" & theInc & "&preview=yes&thispage=" & thispage & makeParam(inhoud)
	end if
	

case "run", ""

	page = request.querystring("page")
	if page <> "" then page = cstr(cdbl(page))

	sql = "select top 1 * from live order by id desc"
	set rs = tmpConnection.execute(sql)
	volgorde = rs("volgorde")
	theArray = split(volgorde, ";")
	if page = "" then page = theArray(0)

	for t=lbound(theArray) to ubound(theArray)
		if theArray(t) = page then
			if t<ubound(theArray) then
				nextpage = theArray(t+1)
			else
				nextpage = theArray(0)
			end if
		end if
	next
	
	sql = "select * from vwcontent where id=" & page
	
	set rs = tmpConnection.execute(sql)
	
	if rs.eof then
		response.redirect "kabelkrant.asp?command=run"
	end if
	
	if not pageIsScheduled(rs) then
		response.redirect "kabelkrant.asp?command=run&page=" & nextpage
	end if
	
	titel = rs("titel")
	inhoud = rs("inhoud")
	bgnr = rs("background")
	special = rs("special")

	sql = "select dur from content where id=" & page
	rs = tmpConnection.execute(sql)

	dur = rs("dur")
	if not isnull(dur) then pauze = dur
	
	sql = "select image from images where id=" & bgnr
	rs = tmpConnection.execute(sql)
	bgImage = rs("image")
	
	if special > 0 then
		sql = "select include from special where id=" & special
		rs = tmpConnection.execute(sql)
		theInc = replace(rs("include"), "\", "/")
	end if

	closeDatabase

	call register(page, titel)
	call setNP(page, titel, inhoud, pauze, bgImage, special, theInc)

	if special > 0 then
		params = split(inhoud, "<br>")
		response.redirect("special/" & theInc & "&thispage=" & page & "&nextpage=" & nextpage & makeParam(inhoud))
	else
		showpage
	end if

end select

sub showpage

titel = trim(titel)

'call register(page, titel)
'call setNP(page, titel, inhoud, pauze, bgImage, special, theInc)

if len(titel) >= 2 then
	if left(titel,1) = "(" and right(titel,1) = ")" then titel = ""
end if

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title><%=titel%></title>
	<LINK REL="stylesheet" TYPE="text/css" HREF="style/kabelkrant.css">
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
	<script src="script/narrowcast.js"></script>
	<script language='javascript'>
		function nextpage() {
			self.location.href = "kabelkrant.asp?command=run&page=<%=nextpage%>";
		}
	</script>
</head>

<body scroll="no" background="images/<%=bgImage%>">

<% if command = "preview" then %>
<style>
	body {
		background-repeat: no-repeat;
		background-color: black;
	}
</style>
<% end if %>

<% if titel <> "" then %><h1><%=titel%></h1><% end if %>

<p>
<%
dispInhoud = ""
line = ""

if isnull(inhoud) then inhoud=""
if inhoud="" and isnull(dur) then pauze = pauze / 2

inhoud = replace(inhoud, "[euro]", "<font face=Arial>&euro;</font>")

inhoud = split(inhoud,"<br>")
inTabel = false

for lines=0 to ubound(inhoud)
	if instr(inhoud(lines),"~") then
		' if instr(inhoud(lines),"@") then teken = "@"
		if instr(inhoud(lines),"~") then teken = "~"
		if not inTabel then
			%><table class="tilde-tabel"><%
			inTabel = true
		end if
		tmpRegel = split(inhoud(lines),teken)
		%><tr><%
		for t=0 to ubound(tmpRegel)
			%><td><%=tmpRegel(t)%></td><%
		next
		%></tr><%
	else
		if inTabel then
			%></table><%
			inTabel = false
		end if
		%><%=inhoud(lines)%><br><%
	end if
next
%>
</p>

<% if command <> "preview" then %>
<script language="JavaScript">
	setTimeout('nextpage()', <%=pauze * 1000%>);
</script>
<% else %>
<div style="position: absolute; visibility: visible; top: 10px; left: 10px; zoom: 2"><input type="button" value="Klaar met voorbeeld" onclick="self.close();"></div>
&nbsp;
<% end if %>

<span id="clock" name="clock" class="underline"></span>

<% if not titel = "" then %>
<script language="JavaScript">
	showtime();
</script>
<% end if %>

</body>
</html>

<%
end sub
%>